<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\validate;

/**
 * 商品验证器
 */
class Product extends ValidateBase
{
    
    // 验证规则
    protected $rule = [
        'id'                => 'require|integer|gt:0',
        'name'              => 'require|length:1,100',
        'category'          => 'require|in:tobacco,alcohol,tea',
        'brand'             => 'length:0,50',
        'specification'     => 'length:0,50',
        'wholesale_price'   => 'float|egt:0',
        'guide_price'       => 'float|egt:0',
        'market_price'      => 'require|float|gt:0',
        'yesterday_price'   => 'float|egt:0',
        'cover_id'          => 'integer|egt:0',
        'img_ids'           => 'length:0,500',
        'is_vip_only'       => 'in:0,1',
        'product_status'    => 'in:0,1',
        'status'            => 'in:0,1',
        'sort'              => 'integer|egt:0',
    ];

    // 验证提示
    protected $message = [
        'id.require'                => '商品ID不能为空',
        'id.integer'                => '商品ID必须为整数',
        'id.gt'                     => '商品ID必须大于0',
        'name.require'              => '商品名称不能为空',
        'name.length'               => '商品名称长度为1-100个字符',
        'category.require'          => '商品分类不能为空',
        'category.in'               => '商品分类必须为tobacco、alcohol或tea',
        'brand.length'              => '品牌长度不能超过50个字符',
        'specification.length'      => '规格长度不能超过50个字符',
        'wholesale_price.float'     => '批发价必须为数字',
        'wholesale_price.egt'       => '批发价不能为负数',
        'guide_price.float'         => '指导价必须为数字',
        'guide_price.egt'           => '指导价不能为负数',
        'market_price.require'      => '行情价不能为空',
        'market_price.float'        => '行情价必须为数字',
        'market_price.gt'           => '行情价必须大于0',
        'yesterday_price.float'     => '昨日价格必须为数字',
        'yesterday_price.egt'       => '昨日价格不能为负数',
        'cover_id.integer'          => '主图ID必须为整数',
        'cover_id.egt'              => '主图ID不能为负数',
        'img_ids.length'            => '多图ID列表长度不能超过500个字符',
        'is_vip_only.in'            => 'VIP专享标识值不正确',
        'product_status.in'         => '商品状态值不正确',
        'status.in'                 => '数据状态值不正确',
        'sort.integer'              => '排序必须为整数',
        'sort.egt'                  => '排序不能为负数',
    ];

    // 应用场景
    protected $scene = [
        'add'       => ['name', 'category', 'market_price', 'product_status'],
        'edit'      => ['id', 'name', 'category', 'market_price', 'product_status'],
        'status'    => ['id', 'product_status'],
        'price'     => ['id', 'market_price'],
    ];
}